import { Checkbox, Form } from "antd";
import type { OrganizeImportsConfig } from "./config";
import ArrayInput from "./ArrayInput";

interface OrganizeImportsProps {
    organizeImports?: OrganizeImportsConfig;
    onChange: (organizeImports: OrganizeImportsConfig) => void;
}

export default function OrganizeImports(props: OrganizeImportsProps) {
    return (
        <Form labelCol={{ span: 3 }}>
            <Form.Item label="开启">
                <Checkbox checked={props.organizeImports?.enabled ?? false} onChange={e => {
                    e.stopPropagation();
                    let organizeImports = props.organizeImports;
                    if (organizeImports == undefined) {
                        organizeImports = {};
                    }
                    organizeImports.enabled = e.target.checked;
                    props.onChange(organizeImports);
                }} />
            </Form.Item>
            {(props.organizeImports?.enabled ?? false) == true && (
                <>
                <Form.Item label="忽略路径">
                        <ArrayInput valueList={props.organizeImports?.ignore ?? []} onChange={value => {
                            let organizeImports = props.organizeImports;
                            if (organizeImports == undefined) {
                                organizeImports = {};
                            }
                            organizeImports.ignore = value;
                            props.onChange(organizeImports);
                        }} />
                    </Form.Item>
                </>
            )}
        </Form>
    );
}